"""
Quoridor II: Student Computer Player

A sample class you may use to hold your state data
Author: Adam Oest (amo9149@rit.edu)
Author: David Fryer (dnf7976@rit.edu)
Author: Mike Yachanin (mry1294@rit.edu)
Author: Isaiah Cote (iyc1257@rit.edu)
"""

from  StudentPlayers.TheFightingPenguins.wallData import WallData
from StudentPlayers.TheFightingPenguins.boardNode import *

class PlayerData(object):
    """A sample class for your player data"""
    
    # Add other slots as needed
    # movePawn is now irrelevant
    __slots__ = ('logger', 'playerId', 'playerLocations', 'numPlayers', 'r', 'c', 'move', 'walls', 'board', 'wallCount', 'movePawn', 'playerHistory',
                  'destination','firstMove','isBlocked')
    
    def __init__(self, logger, playerId, playerLocations, r, c, wallCount, movePawn):
        """
        __init__: 
        Constructs and returns an instance of PlayerData.
            self - new instance
            logger - the engine logger
            playerId - my player ID (0-3)
            playerLocations - list of player coordinates
        """
        
        self.logger = logger
        self.playerId = playerId
        self.playerLocations = playerLocations
        self.numPlayers = len(playerLocations)
        # initialize any other slots you require here
        self.r = r
        self.c = c
        self.walls = []
        self.wallCount = wallCount
        self.board = self.build_board()
        self.movePawn = movePawn
        self.playerHistory = []
        self.playerHistory.append([r,c])
        self.firstMove=True
        self.isBlocked=False
        if(playerId==1 or playerId==3):
            self.destination=0
        elif(playerId==2 or playerId==4):
            self.destination=8

    def build_board(self):
        board = [[],[],[],[],[],[],[],[],[]]
        for row in range(0,9):
            temp=[]
            for col in range(0,9):
                temp.append(BoardNode([row,col],self))
            board[row]=temp
        return board
        
    def __str__(self):
        """
        __str__: PlayerData -> string
        Returns a string representation of the PlayerData object.
            self - the PlayerData object
        """
        result = "PlayerData= " \
                    + "playerId: " + str(self.playerId) \
                    + ", playerLocations: " + str(self.playerLocations) \
                    + ", numPlayers:" + str(self.numPlayers)
                
        # add any more string concatenation for your other slots here
                
        return result
        
    def add_walls(self,r1,r2,c1,c2):
        self.walls.append(WallData(r1,c1,r2,c2))
        if(not self.walls[len(self.walls)-1].vert):
            self.board[r1][c1].neighbors.remove([r1-1,c1])
            self.board[r2][c2-1].neighbors.remove([r2-1,c2-1])
            #####################################################################################
            self.board[r1-1][c1].neighbors.remove([r1,c1])
            self.board[r2-1][c2-1].neighbors.remove([r2,c2-1])
        else:
            self.board[r1][c1].neighbors.remove([r1,c1-1])
            self.board[r2-1][c2].neighbors.remove([r2-1,c2-1])
            #####################################################################################
            self.board[r1][c1-1].neighbors.remove([r1,c1])
            self.board[r2-1][c2-1].neighbors.remove([r2-1,c2])
            
    def getCurLoc(self):
        return self.playerHistory[len(self.playerHistory)-1]
    
    def wallAt(self,r1,c1,r2,c2):
        for wall in self.walls:
            if(wall.start == [r1,c1]):
                return True
        return False